using System;
using System.Data;
using System.Data.OleDb;
using System.IO;
using MySql.Data.MySqlClient;
using LdExpress;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Collections;
namespace LdExpress
{
    public class ProcessDescription
    {
        public long ID = 0;
        public string Name = "";
        public string Code = "";
        public string Description = "";
        public DateTime LastUpdate = DateTime.Now;
        public DateTime DateCreate = DateTime.Now;
        public long UserID = 0;
        public int Type = 0;
        public int IsLock = 0;
        public int ProcessCust = 1;
        public int ProcessDoc = 2;
        public int ProcessSale = 3;
        public int ProcessAccnt = 4;
        public int ProcessRegulation = 5;
        public int ProcessChooseProfile = 6;
        public int ProcessRecruitmentRequirements = 7;
        public int ProcessFreightGuide = 8;
        public int ProcessTruckingGuide = 9;
        public int ProcessSalesRecruitment = 10;
        public int ProcessDocRecruitment = 11;
        public int ProcessAccountingRecruitment = 12;
        public int ProcessTestSales = 13;
        public int ProcessTestDoc = 14;
        public int ProcessTestAccounting = 15;

        public ProcessDescription()
        {
        }

        public ProcessDescription(long lID)
        {
            this.ID = lID;
        }
        public void Save(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            string strTableName = "tbl_ProcessDescription";

            if (ID <= 0) // new object, we insert new record to database
            {
                //ID = long.Parse(DBModule.GetNewID(typeof(Bill), "tbl_bill" , "ID", "ID", cn, trans));
                strSQL = "INSERT INTO " + strTableName + "(" +
                "Name, " +
                "Code, " +
                "Description, " +
                "UserID, " +
                "Type," +
                "IsLock," +
                "DateCreate, " +
                "LastUpdate" +
                ")" +
                "VALUES(" +
                "'" + DBModule.RefineString(Name) + "'," +
                "'" + DBModule.RefineString(Code) + "'," +
                "'" + DBModule.RefineString(Description) + "'," +
                UserID + "," +
                Type + "," +
                IsLock + "," +
                DBModule.RefineDatetime(DateCreate) + "," +
                DBModule.RefineDatetime(LastUpdate) +
                ")";
                DBModule.ExecuteNonQuery(strSQL, cn, trans);
            }
            else // edit object, we update old record in database
            {
                // build SQL statement
                strSQL = "Update " + strTableName + " set " +
                             "Name='" + DBModule.RefineString(Name) + "'" +
                             ",Code='" + DBModule.RefineString(Code) + "'" +
                             ",Description='" + DBModule.RefineString(Description) + "'" +
                             ",UserID=" + UserID +
                             ",Type=" + Type +
                             ",IsLock=" + IsLock +
                    //",DateCreate=" + DBModule.RefineDatetime(DateCreate) + "" +
                             ",LastUpdate=" + DBModule.RefineDatetime(LastUpdate) + "" +
                    " where ID=" + ID.ToString();
                // run SQL statement
                DBModule.ExecuteNonQuery(strSQL, cn, trans);

            }
            //throw new Exception(strSQL);
        }
        public void Delete(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "DELETE FROM tbl_JobDescriptions WHERE ID = " + this.ID.ToString();
            DBModule.ExecuteNonQuery(strSQL, cn, trans);
        }
        public void Load(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            strSQL = "SELECT * FROM tbl_ProcessDescription WHERE ID = " + ID.ToString() + " limit 0,1";

            DataSet ds = DBModule.ExecuteQuery(strSQL, cn, trans);
            //Fill data into this object
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                if (!dr.IsNull("ID"))
                    ID = long.Parse(dr["ID"].ToString());
                if (!dr.IsNull("Name"))
                    Name = dr["Name"].ToString();
                if (!dr.IsNull("Code"))
                    Code = dr["Code"].ToString();
                if (!dr.IsNull("Description"))
                    Description = dr["Description"].ToString();

                if (!dr.IsNull("UserID"))
                    UserID = long.Parse(dr["UserID"].ToString());
                if (!dr.IsNull("IsLock"))
                    IsLock = int.Parse(dr["IsLock"].ToString());
                if (!dr.IsNull("Type"))
                    Type = int.Parse(dr["Type"].ToString());
                if (!dr.IsNull("DateCreate"))
                    DateCreate = DateTime.Parse(dr["DateCreate"].ToString());
                if (!dr.IsNull("LastUpdate"))
                    LastUpdate = DateTime.Parse(dr["LastUpdate"].ToString());
            }
        }
        public void Load(int Type, MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            strSQL = "SELECT * FROM tbl_ProcessDescription WHERE Type = " + Type.ToString() + " limit 0,1";

            DataSet ds = DBModule.ExecuteQuery(strSQL, cn, trans);
            //Fill data into this object
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                if (!dr.IsNull("ID"))
                    ID = long.Parse(dr["ID"].ToString());
                if (!dr.IsNull("Name"))
                    Name = dr["Name"].ToString();
                if (!dr.IsNull("Code"))
                    Code = dr["Code"].ToString();
                if (!dr.IsNull("Description"))
                    Description = dr["Description"].ToString();

                if (!dr.IsNull("UserID"))
                    UserID = long.Parse(dr["UserID"].ToString());
                if (!dr.IsNull("IsLock"))
                    IsLock = int.Parse(dr["IsLock"].ToString());
                if (!dr.IsNull("Type"))
                    Type = int.Parse(dr["Type"].ToString());
                if (!dr.IsNull("DateCreate"))
                    DateCreate = DateTime.Parse(dr["DateCreate"].ToString());
                if (!dr.IsNull("LastUpdate"))
                    LastUpdate = DateTime.Parse(dr["LastUpdate"].ToString());
            }
        }
        public void GetList(string strCondition, string OrderBy, int NumOfItemsPerPage, int PageNo, out int NumberOfPages, out DataSet ds, MySqlConnection cn, MySqlTransaction trans)
        {

            NumberOfPages = 0;
            string strSQL = "";
            ds = null;
            // build SQL statement
            strSQL = "Select * from tbl_ProcessDescription  where 1=1 ";
            if ((strCondition != "") && (strCondition != null))
            {
                strSQL += strCondition;
            }
            if ((OrderBy != null) && (OrderBy != ""))
                strSQL = strSQL + " Order By " + DBModule.RefineString(OrderBy);
            else
                strSQL = strSQL + " Order By ID ASC";
            // run SQL statement
            if (NumOfItemsPerPage > 0)
            {
                ds = DBModule.ExecuteQuery(strSQL, NumOfItemsPerPage, PageNo, out NumberOfPages, cn, trans);
            }
            else
                ds = DBModule.ExecuteQuery(strSQL, cn, trans);
            //return strSQL;
        }
        public void DoSearch(string strCondition, string OrderBy, out DataSet ds, MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            ds = null;
            // build SQL statement
            strSQL = "Select `ID` from tbl_ProcessDescription where 1=1 ";
            if (strCondition.Length > 0)
                strSQL += strCondition;
            if ((OrderBy != null) && (OrderBy != ""))
                strSQL = strSQL + " Order By " + DBModule.RefineString(OrderBy);
            // run SQL statement
            ds = DBModule.ExecuteQuery(strSQL, cn, trans);
        }
    }
}

